from typing import Union
from exceptions import LiquidRenderError
from constants import EMPTY_REPLACEMENT
from filters.manager import FilterManager


@FilterManager.register
def compact(value: list):
    if isinstance(value, list):
        return list(filter(lambda x: x is not None, value))
    raise LiquidRenderError(value)


@FilterManager.register
def concat(value: list, other_list: list):
    if isinstance(value, list) and isinstance(other_list, list):
        value = value.extend(other_list)
        return value
    raise LiquidRenderError(f"value: {value} other_list: {other_list}")


@FilterManager.register
def size(value: Union[str, list]):
    return len(value)


@FilterManager.register
def join(value: list, joint: str):
    return joint.join(value)
